#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    picID = 2;

    //图片
    QPixmap pix("D:\\QT_Projects\\objectTimer\\1.jpg");
    //显示图片
    ui->label->setPixmap(pix);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_startButton_clicked()
{
    //开启定时器，返回定时器编号
    myTimerId = this->startTimer(TIMEOUT);
}


//实现定时器事件函数
//当有多个定时器时，要判断执行哪个定时器
void Widget::timerEvent(QTimerEvent *event){
    if(event->timerId() != myTimerId)
        return;

    QString path("D:\\QT_Projects\\objectTimer\\");
    path += QString::number(picID);
    path += ".jpg";

    QPixmap pix(path);
    ui->label->setPixmap(pix);

    //停止边界
    picID++;
    if (picID == 4)
        picID = 1;
}

void Widget::on_stopButton_clicked()
{
    this->killTimer(myTimerId);
}

